package com.hns.can.master.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hns.can.common.aop.orgTree.DriverInterfaceAnnotation;
import com.hns.can.common.aop.orgTree.LeftOrgAnnotation;
import com.hns.can.common.aop.sedate.SedateAnnotation;
import com.hns.can.common.entity.BaseEntity;
import com.hns.can.master.entity.CommDrvSctBhvInfoEntity;
import com.hns.can.master.entity.CommMftAlmEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hns.can.common.constants.GlobalConst;
import com.hns.can.common.formula.FillCodeDscValue;
import com.hns.can.common.formula.FillParamsVo;
import com.hns.can.common.service.CommonInitParamService;
import com.hns.can.common.vo.CommonParamsVo;
import com.hns.can.master.entity.BaseCarInfoEntity;
import com.hns.can.master.entity.CommCarCurrentLoInfoEntity;
import com.hns.can.master.vo.DriveTrajInfoVo;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.PubUtil;

@Service
public class OperationManageService extends CommonService{

    /**
     * 填充代码描述
     */
    @Autowired
    private FillCodeDscValue codeDscValue;
    
	/**
     * @param params
     * @param request
     * @param response
     * @author:zhangy
     * @email:zhangyu2222z@sina.cn
     * @创建日期:2015年9月7日
     * @功能说明：获取线路实时路况
     */
	@SuppressWarnings("unchecked")
	@Transactional
	public List<CommCarCurrentLoInfoEntity> getRealTimeTrafficStatus(CommonParamsVo params) {
		List<CommCarCurrentLoInfoEntity> selectList = PubUtil
				.convertListMapToObject(sqlMapDao.selectList(
						"operationManager.getRealTimeTrafficStatus", params),
						CommCarCurrentLoInfoEntity.class);
		return selectList;
	}  
	

	/**
	 * 获取制定车辆公司id和线路id
	 * @param params 参数
	 * @return
	 * @author:zhangy
	 * @email:zhangyu2222z@sina.cn
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Transactional
	public List<BaseCarInfoEntity> getCorpAndLine(CommonParamsVo params){
		List list = PubUtil.convertListMapToObject(sqlMapDao.selectList("operationManager.getCorpAndLine", params), BaseCarInfoEntity.class);
		return list;
	}
	
	
	/**
	 * 获取形式记录轨迹
	 * @param entity
	 * @param commonInitParamService
	 * @return
	 * @throws Exception
	 * @author:lan
	 * @email:763836737@qq.com
	 */
	@SuppressWarnings("unchecked")
	@Transactional
	public List<DriveTrajInfoVo> getDriveTrajInfo(CommonParamsVo entity,
			CommonInitParamService commonInitParamService) throws Exception {
		List<DriveTrajInfoVo> selectList = PubUtil.convertListMapToObject(sqlMapDao.selectList("operationManager.getDriveTrajInfo", entity),DriveTrajInfoVo.class);
	    Map<String,String> map = new HashMap<String,String>();
        map.put("licPltNo", GlobalConst.DEFAULT_CACHE_VALUE);  
        FillParamsVo vo = new FillParamsVo("carId", map);
        codeDscValue.fillInfoValue(selectList, new String[]{GlobalConst.CACHE_KEY_BASE_CAR_INFO}, vo);
		return selectList;
	}
	
	
	/**
     * @param params
     * @author:zhangy
     * @email:zhangyu2222z@sina.cn
     * @创建日期:2015年9月7日
     * @功能说明：获取线路偏移经纬度数据
     */
	@SuppressWarnings("unchecked")
	public List<DriveTrajInfoVo> loadShiftRoute(CommonParamsVo entity,
			CommonInitParamService commonInitParamService) throws Exception {
		List<DriveTrajInfoVo> selectList = PubUtil.convertListMapToObject(sqlMapDao.selectList("operationManager.loadShiftRoute", entity),DriveTrajInfoVo.class);
		return selectList;
	}


	/**
	 * 查询驾驶员行为数据
	 * @param conditionVo
	 * @return
	 * @throws Exception
	 * @author:zhangzq
	 * @email:
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Transactional
	@SedateAnnotation()
	@DriverInterfaceAnnotation()
	public List<DriveTrajInfoVo> getDrivingBehaviorList2(CommonParamsVo vo) throws Exception {
		List list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList("operationManager.getDrivingBehaviorList2", vo), DriveTrajInfoVo.class);
		fillCodeDscValue(list);
		return list;
	}

	/**
	 * 查询实时故障
	 * @param vo
	 * @return
	 * @author:zhangzq
	 * @email:
	 */
	@Transactional
	@SedateAnnotation()
	@DriverInterfaceAnnotation()
	public List<DriveTrajInfoVo> getAllRealTimeFailure2(CommonParamsVo vo)throws Exception{
		List list = PubUtil.convertListMapToObject(sqlMapDao.selectList("operationManager.getRealTimeFailure2", vo), DriveTrajInfoVo.class);
		fillCodeDscValue(list);
		Map<String,String> map = new HashMap<String,String>();
		map.put("mftClCode", "MFTC0000");
		codeDscValue.fillCodeDscValue(list, map);
		return list;
	}

	/**
	 * 翻译解释基础名称
	 * @param list
	 * @author:zhangzq
	 * @email:
	 */
	private void fillCodeDscValue(List list) throws Exception{
		Map<String,String> map = new HashMap<String,String>();
		map.put("lineName", GlobalConst.DEFAULT_CACHE_VALUE);
		FillParamsVo vo1 = new FillParamsVo("lineId", map);
		map = new HashMap<String,String>();
		map.put("organName", GlobalConst.DEFAULT_CACHE_VALUE);
		FillParamsVo vo2 = new FillParamsVo("organId", map);
		map = new HashMap<String,String>();
		map.put("drvName", GlobalConst.DEFAULT_CACHE_VALUE);
		FillParamsVo vo3 = new FillParamsVo("drvId", map);
		map = new HashMap<String,String>();
		map.put("licPltNo", GlobalConst.DEFAULT_CACHE_VALUE);
		FillParamsVo vo4 = new FillParamsVo("carId", map);
		codeDscValue.fillInfoValue(list,new String[]{GlobalConst.CACHE_KEY_BASE_LINE_INFO,GlobalConst.CACHE_KEY_BASE_ORGAN,GlobalConst.CACHE_KEY_BASE_DRV_INFO,GlobalConst.CACHE_KEY_BASE_CAR_INFO},vo1,vo2,vo3,vo4);
		map = new HashMap<String,String>();
		map.put("drvSctBhv", "DRV00000");
		codeDscValue.fillCodeDscValue(list, map);
	}
}